<style scoped>
.policy-edit{
    padding-bottom: 35px;
    
}

.pro-list{
    padding-top: 10px;
}
.pro-list h4{
    display: block;
    position: relative;
}

.pro-list h4:before{
    content: '';
    position: absolute;
    height: 0;
    top:8px;
    left: 0;
    width: 100%;
    border-bottom: 1px dotted #d9d9d9;
    
}
.pro-list h4 span{
    display: inline-block;
    background: #fff;
    padding-left: 5px;
    padding-right: 5px;
    position: relative;
    font-weight: normal;
}
.import-left{
    background-color: #f2f2f2;
    overflow: hidden;
}
.import-search{
    padding: 15px 15px 0;
}
.import-list{
    padding: 0 13px;
}
.import-right{
    background-color: #cfebf9;
    padding: 20px 20px 0 20px;
}
.import-right-title{
    overflow: hidden;
}
.import-right-title h3{
    display: inline-block;
    color: #ef8411;
    font-size: 16px;
    line-height: 43px;
}
.import-right-body{
    padding-top: 20px;
    margin-right: -15px;
}
.import-right-body .ivu-form-item{
    margin-bottom: 24px;
}
.import-search .ivu-input-group-append button{
    background-color: #4074e1;
    color: #fff;
}
.import-search .ivu-input-group{
    top: 0;
}
.pd35{
    padding-bottom: 35px;
}
.form-box{
    position: relative;
    overflow: hidden;
}
.fixed-bottom{
    padding-top: 18px;
    height:80px;
    position:fixed; 
    left:210px;
    right:0; 
    bottom:0; 
    z-index: 999;
    text-align: center;
    background-color: rgb(255, 255, 255); 
    box-shadow: 0px 0px 9px 0px rgba(0, 0, 0, 0.28);
}
.sidehide{
    left: 75px;
}
.benefit{
    margin-bottom: 15px;
}
.reset{
    background-color: #5cadff !important;
}
.slot-footer{
    background-color: #f2f2f2;
    overflow: hidden;
    margin: -12px -18px;
    padding: 12px 18px;
}
.bgfff{
    background-color: #fff;
}
.pro-box{
    padding-top: 20px;
    padding-left: 20px;
}
.party-box{
    margin: -16px;
    background-color: #cfebf9;
}
.total-price{
    color: red;
    font-size: 16px;
}
.common-form-body-left{
    width: 75%;
}
.common-form-body-right{
    width:25%;
    padding:0;
    border-radius: 0 2px 2px 0;
}
</style>
<style>
.clearfix:after {
    visibility: hidden;
    display: block;
    content: " ";
    clear: both;
    height: 0;
    line-height: 0;
}

.clearfix {
    zoom: 1;
}
.table-theme .ivu-table-row-highlight .importbtn{
    background-color: #fff;
    color:#fff;
}
</style>

<template>
    <div class="policy-edit">
        <product-title></product-title>
        <div class="form-box">
            <div class="common-box-body common-form-body">
                <Form ref="policyform" :model="policyform" :rules="policy_ruleValidate">
                    <Row>
                        <Col :xs="24" :sm="24" :md="8" :lg="6">
                            <FormItem prop="yun_org_mid" label="归属机构">
                                <Select ref="orgselect"  filterable  placeholder="请选择分支机构" v-model="policyform.yun_org_mid" :transfer=true>
                                    <Option value="">全部</Option>
                                    <Option v-for="item in orglist" :value="item.id" :key="item.id">{{item.shortn}}</Option>                                                                                                                                       
                                </Select>
                            </FormItem>
                        </Col>
                    </Row>   
                </Form>
            </div>
            <div class="common-box-header">
                <h3>录单员信息</h3>
                <Button @click="importEmployee(1)" class="fr mt7" type="warning" icon="icon iconfont icon-daoru">导入录单员</Button>
            </div>
            <div class="common-box-body common-form-body">
                <Form ref="entering" :model="entering" :rules="entering_ruleValidate">
                    <Row>
                        <Col :xs="24" :sm="24" :md="8" :lg="6">
                            <FormItem prop="job_code" label="录单工号">
                                <Input type="text" v-model="entering.job_code "  placeholder="请导入录单工号" disabled></Input>
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="8" :lg="6">
                            <FormItem prop="name" label="录单员姓名">                                
                                <Input type="text" v-model="entering.name"  placeholder="请导入录单员姓名" disabled></Input>                               
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="8" :lg="12">
                            <FormItem prop="datetime" label="录单时间">
                                <DatePicker  type="date" :options="options3"placeholder="请选择录单时间" v-model="entering.datetime" @on-change="datachange($event,entering,'date')"></DatePicker>
                            </FormItem>
                        </Col>
                    </Row>   
                </Form>
            </div>
            <div class="common-box-header">
                <h3>业务员信息</h3>
                <Button @click="importEmployee(2)" class="fr mt7" type="warning" icon="icon iconfont icon-daoru">导入业务员</Button>
            </div>
            <div class="common-box-body common-form-body">
                <Form ref="agent" :model="agent" :rules="agent_ruleValidate">
                    <Row>
                        <Col :xs="24" :sm="24" :md="8" :lg="6">
                            <FormItem prop="oname" label="机构">
                                <Input type="text" v-model="agent.oname"  placeholder="请导入机构" disabled></Input>
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="8" :lg="6">
                            <FormItem prop="dept_name" label="部门">                                
                                <Input type="text" v-model="agent.dept_name"  placeholder="请导入部门" disabled></Input>                               
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="8" :lg="6">
                            <FormItem prop="rank_name" label="职级">
                                <Input type="text" v-model="agent.rank_name"  placeholder="请导入职级" disabled></Input>
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="8" :lg="6">
                            <FormItem prop="job_code" label="工号">                                
                                <Input type="text" v-model="agent.job_code"  placeholder="请导入工号" disabled></Input>                               
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="8" :lg="6">
                            <FormItem prop="name" label="姓名">
                                <Input type="text" v-model="agent.name"  placeholder="请导入姓名" disabled></Input>
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="8" :lg="6">
                            <FormItem label="关系上属">                                
                                <Input type="text" v-model="agent.leader_name"  placeholder="请导入关系上属" disabled></Input>                               
                            </FormItem>
                        </Col>
                        <Col :xs="24" :sm="24" :md="8" :lg="12">
                            <FormItem label="推荐人">                                
                                <Input type="text" v-model="agent.rec_name"  placeholder="请导入推荐人" disabled></Input>                               
                            </FormItem>
                        </Col>
                    </Row>   
                </Form>
            </div>
            <div class="mt20 pro-person">
                <Tabs type="card" :animated=false>
                    <TabPane label="保单信息" name="name1">
                        <div class="common-box-body common-form-body">
                            <Form ref="policyform" :model="policyform" :rules="policy_ruleValidate">
                                <Row>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="cid" label="保险公司">
                                            <!-- <Select v-model="policyform.cid" @on-change="companychange($event)" filterable remote label-in-value :remote-method="remoteCom" :loading="proloading"  placeholder="选择保险公司">  
                                                <Option v-for="(option, index) in comoptions" :value="option.value" :key="index">{{option.label}}</Option>                               
                                            </Select> -->
                                            <Select v-model="policyform.cid" label-in-value @on-change="cid_change($event)"  filterable  placeholder="选择保险公司" :transfer=true>  
                                                <Option v-for="(option, index) in comoptions" :value="option.cid" :key="option.cid">{{option.name}}</Option>                               
                                            </Select>
                                        </FormItem>
                                    </Col>                        
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="name" label="保险计划">                                
                                            <Input type="text" v-model="policyform.name"  placeholder="请填写保险计划名"></Input>                               
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem  label="投保单号码" prop="insure_num">
                                            <Input type="text" v-model="policyform.insure_num"  placeholder="请导入投保单号码"></Input>   
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="policy_num" label="保单号码">
                                            <Input type="text" v-model="policyform.policy_num"  placeholder="请导入承保单号码"></Input>   
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="pay_period" label="交费期间">  
                                            <!-- <Select :disabled="pay_period_disable" v-model="policyform.pay_period" placeholder="请导入交费期间">
                                                <Option v-for="item in policypay_period" :value="item" :key="item">{{item}}</Option>                                   
                                            </Select>                                           -->
                                            <Input disabled class="common-form-body-left" type="text" v-model="policyform.pay_period"  placeholder="请导入交费期间"></Input><Button class="common-form-body-right" @click="openPayperiodModal"  type="primary">添加</Button>  
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="period" label="保险期间">
                                            <Input disabled class="common-form-body-left" type="text" v-model="policyform.period"  placeholder="请导入保险期间"></Input><Button class="common-form-body-right" @click="openPeriodModal"  type="primary">添加</Button>  
                                        </FormItem>
                                    </Col>  
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="pay_type" label="交费方式">
                                            <Select v-model="policyform.pay_type" placeholder="请选择交费方式">
                                                <Option value="期交">期交</Option>
                                                <Option value="一次性交">一次性交</Option>
                                            </Select>
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="premium" label="保费">
                                            <Input disabled type="text" v-model="policyform.premium"  placeholder="请导入保费"></Input>   
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem label="短期消费型">
                                            <Select v-model="policyform.is_short"  placeholder="请选择是否短期消费型">
                                                <Option value="1">是</Option>
                                                <Option value="2">否</Option>
                                            </Select>
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="insure_datetime" label="投保日期">
                                                <DatePicker type="date" @on-change="datachange($event,policyform,'insure_date')" v-model="policyform.insure_datetime" placeholder="请选择投保日期" :transfer=true placement="top"></DatePicker>  
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="underwrite_datetime" label="承保日期">
                                                <DatePicker type="date" @on-change="datachange($event,policyform,'underwrite_date')" v-model="policyform.underwrite_datetime" placeholder="请选择承保日期" :transfer=true placement="top"></DatePicker>  
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="effect_datetime" label="生效日期">
                                                <DatePicker type="date" @on-change="datachange($event,policyform,'effect_date')" v-model="policyform.effect_datetime" placeholder="请选择生效日期" :transfer=true placement="top"></DatePicker>  
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="receipt_datetime" label="回执日期">
                                                <DatePicker type="date" @on-change="datachange($event,policyform,'receipt_date')" v-model="policyform.receipt_datetime" placeholder="请选择回执日期" :transfer=true placement="top"></DatePicker>  
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="visit_datetime" label="回访日期">
                                                <DatePicker type="date" @on-change="datachange($event,policyform,'visit_date')" v-model="policyform.visit_datetime" placeholder="请选择回访日期" :transfer=true placement="top"></DatePicker>  
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="withdraw_datetime" label="撤单时间">
                                                <DatePicker type="date" @on-change="datachange($event,policyform,'withdraw_date')" v-model="policyform.withdraw_datetime" placeholder="请选择撤单时间" :transfer=true placement="top"></DatePicker>  
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="terminal_datetime" label="终止时间">
                                                <DatePicker type="date" @on-change="datachange($event,policyform,'terminal_date')" v-model="policyform.terminal_datetime" placeholder="请选择终止时间" :transfer=true placement="top"></DatePicker>  
                                        </FormItem>
                                    </Col>  
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="settlement_datetime" label="计绩年月">
                                                <DatePicker type="month" format="yyyy-MM" @on-change="datachange($event,policyform,'settlement_date')" v-model="policyform.settlement_datetime" placeholder="请选择计绩年月" :transfer=true placement="top"></DatePicker>  
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="status" label="保单状态">
                                            <Select v-model="policyform.status" placeholder="请选择保单状态">
                                                <Option value="1">预收件</Option>
                                                <Option value="2">承保件</Option>
                                                <Option value="3">契撤件</Option>
                                                <Option value="4">停效件</Option>
                                                <Option value="5">失效件</Option>
                                                <Option value="6">解约件</Option>
                                                <Option value="7">终止件</Option>
                                            </Select>
                                        </FormItem>
                                    </Col>                                             
                                </Row>   
                            </Form>
                        </div>
                        <div class="common-box-header">
                            <h3>投保人</h3>
                            <Button @click="importapplicant(3)" :disabled="hasagent" class="fr mt7" type="warning" icon="icon iconfont icon-daoru">导入投保人</Button>
                        </div>
                        <div class="common-box-body common-form-body pd35">
                            <Form ref="applicant" :model="applicant" :rules="applicant_ruleValidate">
                                <Row>                                   
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="name" label="姓名">
                                            <Input disabled type="text" v-model="applicant.name"  placeholder="请导入姓名"></Input>   
                                        </FormItem>
                                    </Col>  
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="id_type" label="证件类型">
                                            <Select disabled  placeholder="请导入证件类型" v-model="applicant.id_type" :transfer=true placement="top">
                                                <Option value="身份证">身份证</Option>
                                                <Option value="护照">护照</Option>
                                                <Option value="军官证">军官证</Option>
                                                <Option value="港澳居民来往内地通行证">港澳居民来往内地通行证 </Option>
                                                <Option value="其他">其他</Option>
                                            </Select>  
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="8" :lg="6" v-if="hasIdCard">
                                        <FormItem prop="id_number"  :rules="idrule" label="证件号码" key="id_number_input">
                                            <Input disabled  @on-change="idcardchange($event,applicant)"  placeholder="请导入证件号码" v-model="applicant.id_number"></Input>   
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="8" :lg="6" v-else>
                                        <FormItem   label="证件号码" key="no_id_number" >
                                            <Input disabled  @on-change="idcardchange($event,applicant)"  placeholder="请导入证件号码" v-model="applicant.id_number"></Input>   
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="mobile" label="联系电话">
                                            <Input disabled   placeholder="请导入联系电话" v-model="applicant.mobile"></Input>   
                                        </FormItem>
                                    </Col>
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="sex" label="性别">
                                            <Select disabled  placeholder="请导入性别" v-model="applicant.sex">
                                                <Option value="1">男</Option>
                                                <Option value="2">女</Option>
                                            </Select>   
                                        </FormItem>
                                    </Col>  
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="birthdaytime" label="出生日期">
                                             <DatePicker disabled type="date" @on-change="datachange($event,applicant,'birthday')" v-model="applicant.birthdaytime" placeholder="请导入出生日期" :transfer=true placement="top"></DatePicker>  
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="com_name" label="工作单位">
                                            <Input disabled type="text" v-model="applicant.com_name"  placeholder="请导入工作单位"></Input>   
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="profession" label="职业/工种">
                                            <Input disabled type="text" v-model="applicant.profession" placeholder="请导入职业/工种"></Input>   
                                        </FormItem>
                                    </Col>  
                                    <Col :xs="24" :sm="24" :md="12" :lg="12">
                                        <FormItem prop="home_address" label="详细地址">
                                            <Input disabled type="text" v-model="applicant.home_address" placeholder="请导入详细地址"></Input>   
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="postcode" label="邮编">
                                            <Input disabled type="text" v-model="applicant.postcode" placeholder="请导入邮编"></Input>   
                                        </FormItem>
                                    </Col> 
                                    <Col :xs="24" :sm="24" :md="8" :lg="6">
                                        <FormItem prop="email" label="Email">
                                            <Input disabled type="text" v-model="applicant.email"  placeholder="请导入Email"></Input>   
                                        </FormItem>
                                    </Col>                                                        
                                </Row>   
                            </Form>
                        </div>
                        <div class="common-box-header mt20">
                            <h3>关系人列表</h3>                                                          
                            <Button class="fr mt7 ml5" @click="open_party_modal" type="primary" icon="icon iconfont icon-addOnly">新增关系人</Button>
                        </div>
                        <div class="mt20">
                            <Table stripe border :columns="partytable" :data="firendlist"></Table>
                        </div>
                        <div class="common-box-header mt20">
                            <h3>险种列表</h3>  <span class="total-price">总保费：{{totalprice}}  </span>                                                      
                            <Button class="fr mt7 ml5" @click="open_pro_modal" type="primary" icon="icon iconfont icon-addOnly">新增险种</Button>
                        </div>                       
                        <div class="mt20"> 
                            <Table stripe border :columns="protable" :data="prodata"></Table>
                        </div>
                        <div class="common-box-header mt20">
                            <h3>受益人</h3>
                            受益方式：
                            <RadioGroup v-model="beneficiary_type"  @on-change="benefit_change($event)">
                                <Radio label="指定受益"></Radio>
                                <Radio label="法定受益"></Radio>                                            
                            </RadioGroup>  
                            <Button @click="importbenfit()" :disabled="hasapp" class="fr mt7" type="warning" icon="icon iconfont icon-daoru">新增受益人</Button>                        
                        </div>
                        <div class="mt20">
                            <Table stripe border :columns="benefittable" :data="benefitdata"></Table>
                        </div> 
                    </TabPane>
                    <!-- <TabPane label="投保险种信息" name="name2">
                        
                        
                        
                    </TabPane> -->
                </Tabs>
            </div>
            <div :class="slidetoggle?'fixed-bottom':'fixed-bottom sidehide' ">
                <Button type="primary" v-if="$isShow('policy/create')" @click="sendpolicy" shape="circle" icon="icon iconfont icon-dui">提交保单信息</Button>
                <Button type="primary" @click="cancelpolicy" class="ml20 reset" shape="circle" icon="icon iconfont icon-tableresetpassword">返回</Button>
            </div> 
        </div>
        
         <Modal v-model="importemployee" :mask-closable='closeable' width="860" title="导入员工信息" :loading="loading">
            <div class="modal-body">            
                <Row>
                    <Col span="24">
                        <div class="import-left">
                            <div class="common-box-body">
                                <div class="import-search">
                                    <Form ref="formInline">
                                        <Form-item label="姓名">
                                            <Input placeholder="请输入姓名" v-model="searchemploy">
                                                <Button slot="append" @click="searchemp" type="primary" icon="icon iconfont icon-sousuo"></Button>
                                            </Input>
                                        </Form-item> 
                                    </Form>
                                </div> 
                                <div class="import-list">
                                    <Table :loading="tableloading" :show-header=false stripe height="415" :columns="columns" :data="emplist"></Table>
                                </div>                             
                            </div>
                        </div> 
                    </Col>
                </Row> 
            </div>                      
            <div slot="footer"></div>          
        </Modal>
        <Modal v-model="importcustomer" :mask-closable='closeable' width="860" title="导入投保人" @on-ok="surebtn" :loading="loading">
            <div class="modal-body">            
                <Row>
                    <Col span="12">
                        <div class="import-left">
                            <div class="common-box-body">
                                <div class="import-search">
                                    <Form ref="formInline" >
                                        <Form-item label="姓名">
                                            <Input v-model="searchcustom" placeholder="请输入姓名">
                                                <Button @click="getcustomer(1)" slot="append" type="primary" icon="icon iconfont icon-sousuo"></Button>
                                            </Input>
                                        </Form-item> 
                                    </Form>
                                </div> 
                                <div class="import-list table-theme">
                                    <Table :loading="tableloading" ref="currentRowTable" @on-current-change="tableCurrentChange($event)" size="large" stripe highlight-row border :show-header=false   height="455" :columns="columnsuser" :data="appCustomerList"></Table>
                                </div>                                                          
                            </div>
                            <div style="overflow:hidden;margin:20px;">
                                <Page :total="apptotal" show-total @on-change="pageChange"></Page>
                            </div>  
                        </div> 
                    </Col>
                    <Col span="12">
                        <div class="import-right">
                            <div class="import-right-title">
                                <h3>详细信息</h3>
                                <Button class="fr mt7 ml5" v-show="canedit" @click="addcustomerbtn" type="success">新增</Button>
                                <Button class="fr mt7" v-show="canedit" :disabled="customerEdit" @click="editcustomerbtn" type="warning">编辑</Button>
                                <Button class="fr mt7 ml5" v-show="!canedit" @click="cancelcustomer" type="warning">取消</Button>                                     
                                <Button class="fr mt7" v-show="!canedit" @click="savecustomer" type="success">保存</Button>  
                            </div>
                            <div class="import-right-body">
                                <div class="common-box-body">
                                    <Form ref="customer" :model="customer" :rules="customer_ruleValidate">
                                        <Row>
                                            <Col span="24">
                                                <Form-item prop="name" label="姓名">
                                                    <Input v-model="customer.name" :disabled="canedit" placeholder="请输入姓名"></Input>
                                                </Form-item>                                                
                                            </Col>
                                            <Col span="24">
                                                <Form-item  prop="id_type" label="证件类型">
                                                    <Select  v-model="customer.id_type" :disabled="canedit"  placeholder="请选择证件类型">
                                                        <Option value="身份证">身份证</Option>
                                                        <Option value="护照">护照</Option>
                                                        <Option value="军官证">军官证</Option>
                                                        <Option value="港澳居民来往内地通行证">港澳居民来往内地通行证 </Option>
                                                        <Option value="其他">其他</Option>
                                                    </Select>  
                                                </Form-item> 
                                            </Col>
                                            <!-- id_number: [
                    { required: true, pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/, message: '请填写证件号', trigger: 'blur' }
                ], -->
                                            <Col span="24"  v-if="customer.id_type == '身份证'">       
                                                <Form-item prop="id_number"  :rules="idrule" label="证件号码" key="id_number_input">
                                                    <Input @on-change="idcardchange($event,customer)"  v-model="customer.id_number" :disabled="canedit" placeholder="请输入证件号码"></Input> 
                                                </Form-item>                                              
                                            </Col>
                                            <Col span="24" v-else >                                          
                                                <Form-item  label="证件号码" key="no_id_number_input">
                                                    <Input @on-change="idcardchange($event,customer)"  v-model="customer.id_number" :disabled="canedit" placeholder="请输入证件号码"></Input> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <Form-item prop="birthdaytime" label="出生日期">
                                                    <DatePicker v-model="customer.birthdaytime" @on-change="datachange($event,customer,'birthday')" :disabled="canedit" placeholder="请选择"></DatePicker> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="12">
                                                <Form-item prop="sex"  label="性别">
                                                    <Select v-model="customer.sex" :disabled="canedit"  placeholder="请选择性别">
                                                        <Option value="1">男</Option>
                                                        <Option value="2">女</Option>
                                                    </Select>  
                                                </Form-item> 
                                            </Col>
                                            <Col span="12">
                                                <Form-item label="手机号码">
                                                    <Input v-model="customer.mobile" :disabled="canedit" value="18837180435" placeholder="请输入手机号码"></Input>  
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <Form-item label="工作单位">
                                                    <Input v-model="customer.com_name" :disabled="canedit" placeholder="请输入工作单位"></Input> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <Form-item label="职业/工种">
                                                    <Input v-model="customer.profession" :disabled="canedit" placeholder="请输入职业/工种"></Input> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="12">
                                                <Form-item label="邮编">
                                                    <Input v-model="customer.postcode" :disabled="canedit" placeholder="请输入邮编"></Input> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="12">
                                                <Form-item label="Email">
                                                    <Input v-model="customer.email" :disabled="canedit" placeholder="请输入Email"></Input> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <Form-item label="详细地址">
                                                    <Input v-model="customer.home_address" :disabled="canedit" placeholder="请输入详细地址"></Input> 
                                                </Form-item> 
                                            </Col>
                                        </Row>
                                    </Form>
                                </div>
                            </div>                            
                        </div>
                    </Col>
                </Row> 
            </div>                      
            <div slot="footer" class="slot-footer">  
                <Button type="ghost" size="large" @click="cancel" class="fr ml10 bgfff">取消</Button>             
                <Button type="primary"  size="large" @click="importapp" :disabled="hasctmid" class="fr ">确定</Button>   
            </div>            
        </Modal>
        <Modal v-model="importbenefit" :mask-closable='closeable' width="445" title="导入受益人" :loading="loading">
            <div class="modal-body">            
                <Row>
                    <Col span="24">
                        <Form :model="benefit" ref="benefit">
                            <div class="import-search common-box-body">                          
                                <Form-item label="受益人">
                                    <Select  :disabled="!canedit" label-in-value @on-change="bftchange($event)" placeholder="请选择" :transfer=true>
                                        <Option v-for="(item,index) in firendlist" :key="item.customer_id" :value="item.customer_id">{{item.name}}-{{item.id_number}}-{{item.relation}}</Option>                                  
                                    </Select>  
                                </Form-item>                            
                            </div> 
                            <div class="import-right">
                                <div class="import-right-title">
                                    <Button class="fr mt7 ml5" @click="addbenefit" v-show="canedit" type="success">新增</Button>
                                    <Button class="fr mt7" :disabled="hasben" @click="editbenefit" v-show="canedit" type="warning">编辑</Button>
                                    <Button class="fr mt7 ml5" v-show="!canedit" @click="cancelbenefit" type="warning">取消</Button>                                     
                                    <Button class="fr mt7" v-show="!canedit" @click="sevebenefit" type="success">保存</Button>                                       
                                </div>
                                <div class="import-right-body">
                                    <div class="common-box-body">
                                        <Row>
                                            <Col span="24">
                                                <Form-item label="姓名">
                                                    <Input v-model="benefit.name" :disabled="canedit" placeholder="请输入姓名"></Input>
                                                </Form-item>                                                
                                            </Col>
                                            <Col span="24">
                                                <Form-item label="证件类型">
                                                    <Select v-model="benefit.id_type" :disabled="canedit"  placeholder="请选择证件类型">
                                                        <Option value="身份证">身份证</Option>
                                                        <Option value="护照">护照</Option>
                                                        <Option value="军官证">军官证</Option>
                                                        <Option value="港澳居民来往内地通行证">港澳居民来往内地通行证 </Option>
                                                        <Option value="其他">其他</Option>
                                                    </Select>  
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <Form-item label="证件号码">
                                                    <Input  @on-change="idcardchange($event,benefit)" v-model="benefit.id_number" :disabled="canedit" placeholder="请输入证件号码"></Input> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="12">
                                                <Form-item label="性别">
                                                    <Select v-model="benefit.sex" :disabled="canedit"  placeholder="请选择性别">
                                                        <Option value="1">男</Option>
                                                        <Option value="2">女</Option>
                                                    </Select>  
                                                </Form-item> 
                                            </Col>
                                            <Col span="12">
                                                <Form-item label="出生日期">
                                                    <DatePicker v-model="benefit.birthdaytime"  :disabled="canedit" type="date" placeholder="请选择"></DatePicker> 
                                                </Form-item> 
                                            </Col>
                                            <Col span="24">
                                                <FormItem  label="与投保人关系">
                                                    <Select v-model="benefit.relation" :disabled="canedit" placeholder="请选择" :transfer=true placement="top">
                                                        <Option value="本人">本人</Option>
                                                        <Option value="配偶">配偶</Option>
                                                        <Option value="父母">父母</Option>
                                                        <Option value="子女">子女</Option>
                                                        <Option value="兄弟姐妹">兄弟姐妹</Option>
                                                        <Option value="其他">其他</Option>
                                                    </Select>   
                                                </FormItem>
                                            </Col>
                                            <Col span="12">
                                                <FormItem label="受益顺序">
                                                    <Select v-model="benefit.order"  placeholder="请选择" :transfer=true placement="top">
                                                        <Option value="1">1</Option>
                                                        <Option value="2">2</Option>
                                                        <Option value="3">3</Option>
                                                        <Option value="4">4</Option>
                                                        <Option value="5">5</Option>
                                                    </Select>   
                                                </FormItem>
                                            </Col>
                                            <Col span="12">
                                                <FormItem prop="scale" label="受益比例">
                                                    <Input v-model="benefit.scale" type="text"  placeholder="请输入受益比例"></Input>   
                                                </FormItem>
                                            </Col> 
                                        </Row>                                       
                                    </div>
                                </div>                            
                            </div>
                        </Form>
                    </Col>
                </Row> 
            </div>                      
            <div slot="footer" class="slot-footer">  
                <Button type="ghost" size="large" @click="cancelbenefitbtn" class="fr ml10 bgfff">取消</Button>             
                <Button type="primary" :disabled="hasben" @click="importbenefitbtn"  size="large" class="fr ">确定</Button>   
            </div>   
        </Modal>
        <Modal v-model="importpro" :mask-closable='closeable' width="445" title="新增险种" @on-ok="surebtn" :loading="loading">
            <div class="modal-body">           
                <Row>
                    <Form ref="insurances" :model="insurances" :rules="insurances_ruleValidate">
                    <Col span="24">
                        <div class="common-box-header">
                            <h3>险种信息</h3>
                        </div> 
                        <div class="pro-box">
                            <div class="common-box-body">                               
                                <Row>
                                    <Col span="24">
                                        <Form-item prop="insured_id" label="被保人">
                                            <Select  v-model="insurances.insured_id" label-in-value	  @on-change="insured_change($event)"  placeholder="请选择">
                                                 <Option v-for="(item,index) in firendlist" :key="item.customer_id" :value="item.customer_id">{{item.name}}-{{item.id_number}}-{{item.relation}}</Option>                                                           
                                            </Select>  
                                        </Form-item> 
                                    </Col>
                                    <Col span="24">
                                        <Form-item prop="is_main" label="险种主副">
                                            <Select  v-model="insurances.is_main" @on-change="is_main_change"  placeholder="请选择">
                                                <Option value="1">主险</Option>
                                                <Option value="2">附加险</Option>                                
                                            </Select>  
                                        </Form-item> 
                                    </Col>
                                    <Col span="24">
                                        <FormItem prop="mongo_id" label="险种名称">
                                            <Select v-model="insurances.mongo_id" @on-change="pro_change($event)" label-in-value  filterable   placeholder="请选择险种名称">
                                                <Option v-for="(option, index) in options1" :value="option.mongo_id" :key="option.mongo_id">{{option.name}}</Option>
                                            </Select>  
                                        </FormItem>
                                    </Col>
                                    <Col span="24">
                                        <FormItem prop="period" label="保险期间" >
                                            <Select ref="period" v-model="insurances.period"  placeholder="请选择">
                                                <Option v-for="(item, index) in insurances.periodarry" :value="item" :key="item">{{item}}</Option>
                                            </Select>  
                                        </FormItem>
                                    </Col>
                                    <Col span="24">
                                        <FormItem prop="pay_period" label="交费期间">
                                            <Select v-model="insurances.pay_period" placeholder="请选择">
                                                 <Option v-for="(item, index) in insurances.pay_periodarry" :value="item" :key="item">{{item}}</Option>
                                            </Select>  
                                        </FormItem> 
                                    </Col>
                                    <Col span="24">
                                        <FormItem prop="premium" label="保费">
                                            <Input type="text" v-model="insurances.premium" placeholder="请输入保费"></Input>   
                                        </FormItem>
                                    </Col>
                                    <Col span="24"  class="input-select">
                                        <FormItem prop="amount">
                                            <Input v-model="insurances.amount" >
                                                <Select v-model="insurances.type" slot="prepend" style="width:120px">
                                                    <Option value="保险金额">保险金额</Option>
                                                    <Option value="档次/计划">档次/计划</Option>
                                                    <Option value="日额">日额</Option>
                                                    <Option value="份数">份数</Option>
                                                </Select>
                                            </Input>    
                                        </FormItem> 
                                    </Col>
                                </Row>                                                               
                            </div>
                        </div> 
                    </Col>
                    </Form>
                     
                </Row> 
            </div>                      
            <div slot="footer" class="slot-footer">  
                <Button type="ghost" size="large" @click="cancel_insurances" class="fr ml10 bgfff">取消</Button>             
                <Button type="primary"  size="large" @click="import_insurances" :disabled="hasctmid" class="fr ">确定</Button>   
            </div>            
        </Modal>
        <Modal v-model="party_modal" :mask-closable='closeable' width="860" title="新增关系人" @on-ok="surebtn" :loading="loading">
            <Row class="party-box">
                <Col span="12">
                    <div class="import-left">
                        <div class="common-box-body">
                            <div class="import-search">
                                <Form ref="formInline" >
                                    <Form-item label="姓名">
                                        <Input v-model="searchcustom" placeholder="请输入姓名">
                                            <Button @click="getcustomer(1)" slot="append" type="primary" icon="icon iconfont icon-sousuo"></Button>
                                        </Input>
                                    </Form-item> 
                                </Form>
                            </div> 
                            <div class="import-list table-theme">
                                <Table :loading="tableloading" ref="currentRowTable" @on-current-change="relationCurrentChange($event)" size="large" stripe highlight-row border :show-header=false   height="455" :columns="columnsuser" :data="appCustomerList"></Table>
                            </div>                                                          
                        </div>
                        <div style="overflow:hidden;margin:20px;">
                            <Page :total="apptotal" show-total @on-change="pageChange"></Page>
                        </div>  
                    </div>
                </Col>
                <Form ref="insured" :model="insured" :rules="insured_ruleValidate">
                    <Col span="12">
                        <div class="import-right"> 
                            <div class="import-right-title">
                                <h3>详细信息</h3>
                                <Button class="fr mt7 ml5" v-show="re_canedit" @click="addrelationbtn" type="success">新增</Button>
                                <Button class="fr mt7" v-show="re_canedit" @click="editrelationbtn" type="warning">编辑</Button>
                                <Button class="fr mt7 ml5" v-show="!re_canedit" @click="cancelrelation" type="warning">取消</Button>                                     
                                <Button class="fr mt7" v-show="!re_canedit" @click="saverelation" type="success">保存</Button>  
                            </div>
                            <div class="import-right-body">                          
                                <div class="common-box-body">                                   
                                    <Row>
                                        <Col span="24">
                                            <Form-item prop="name" label="姓名">
                                                <Input  v-model="insured.name" :disabled="re_canedit" placeholder="请输入姓名"></Input>
                                            </Form-item>                                                
                                        </Col>
                                        <Col span="24">
                                            <FormItem prop="relation"  label="与投保人关系">
                                                <Select  v-model="insured.relation" :disabled="re_canedit" placeholder="请选择" :transfer=true placement="top">
                                                    <Option value="本人">本人</Option>
                                                    <Option value="配偶">配偶</Option>
                                                    <Option value="父母">父母</Option>
                                                    <Option value="子女">子女</Option>
                                                    <Option value="兄弟姐妹">兄弟姐妹</Option>
                                                    <Option value="其他">其他</Option>
                                                </Select>   
                                            </FormItem>
                                        </Col>
                                        <Col span="24">
                                            <Form-item prop="id_type" label="证件类型">
                                                <Select   v-model="insured.id_type" :disabled="re_canedit"  placeholder="请选择证件类型">
                                                    <Option value="身份证">身份证</Option>
                                                    <Option value="护照">护照</Option>
                                                    <Option value="军官证">军官证</Option>
                                                    <Option value="港澳居民来往内地通行证">港澳居民来往内地通行证 </Option>
                                                    <Option value="其他">其他</Option>
                                                </Select>  
                                            </Form-item> 
                                        </Col>
                                        <Col span="24" v-if="insured.id_type == '身份证'">
                                            <Form-item prop="id_number" label="证件号码" key="id_number_input">
                                                <Input  @on-change="idcardchange($event,insured)" :disabled="re_canedit"  v-model="insured.id_number" placeholder="请输入证件号码"></Input> 
                                            </Form-item> 
                                        </Col>
                                        <Col span="24" v-else >
                                            <Form-item  label="证件号码" key="no_id_number_input" prop="id_number">
                                                <Input  @on-change="idcardchange($event,insured)" :disabled="re_canedit"  v-model="insured.id_number" placeholder="请输入证件号码"></Input> 
                                            </Form-item> 
                                        </Col>
                                        <Col span="12">
                                            <Form-item prop="birthdaytime" label="生日">
                                                <DatePicker  v-model="insured.birthdaytime" :disabled="re_canedit" @on-change="datachange($event,insured,'birthday')" placeholder="请选择"></DatePicker> 
                                            </Form-item> 
                                        </Col>
                                        <Col span="12">
                                            <Form-item prop="sex"  label="性别">
                                                <Select   v-model="insured.sex"  :disabled="re_canedit" placeholder="请选择">
                                                    <Option value="1">男</Option>
                                                    <Option value="2">女</Option>
                                                </Select>  
                                            </Form-item> 
                                        </Col>
                                        <Col span="12">
                                            <Form-item prop="insured_mobile" label="手机号">
                                                <Input   v-model="insured.mobile" :disabled="re_canedit" placeholder="请输入手机号"></Input> 
                                            </Form-item> 
                                        </Col>
                                        <Col span="12">
                                            <Form-item label="工种">
                                                <Input   v-model="insured.profession" :disabled="re_canedit" placeholder="请输入工种/职业"></Input> 
                                            </Form-item> 
                                        </Col>                                        
                                    </Row>
                                </div>
                            </div>                            
                        </div>
                    </Col>
                </Form>
            </Row>    
            <div slot="footer" class="slot-footer">  
                <Button type="ghost" size="large" @click="cancel_party" class="fr ml10 bgfff">取消</Button>             
                <!-- <Button type="primary"   size="large" @click="import_party" :disabled="hasctmid" class="fr ">确定</Button>    -->
            </div>  
        </Modal>
        <Modal v-model="pay_periodModal" title="选择交费期间">
            <div style="text-align:center">
                <RadioGroup v-model="pay_periodRadio">
                    <Radio label="金斑蝶"></Radio>
                    <Radio label="爪哇犀牛"></Radio>
                    <Radio label="印度黑羚"></Radio>
                </RadioGroup>
            </div>
            <div slot="footer">
                
            </div>
        </Modal>
        <Modal v-model="periodModal" title="选择保险期间">
            <div style="text-align:center">
                <RadioGroup v-model="periodRadio">
                    <Radio label="金斑蝶"></Radio>
                    <Radio label="爪哇犀牛"></Radio>
                    <Radio label="印度黑羚"></Radio>
                </RadioGroup>
            </div>
            <div slot="footer">
                
            </div>
        </Modal>  
        <Spin size="large" fix v-if="spinShow"></Spin>     
    </div>
</template>

<script>
import Vue from 'vue';
import productTitle from '../../components/productTitle'
import { formatTime } from '../../libs/time'
import { getByName , getById} from '../../api/employee'
import { AgentByName } from '../../api/customer'
import { proGetByName } from '../../api/product_v2' 
import { getListByCom , getDetailByIdProduct } from '../../api/product'
import { parteGetByName } from '../../api/parter'
import { policyCreate } from '../../api/policy'
import { getListByName } from '../../api/yun_org' 
import { getByNameCustomer , createCustomer , getDetailById , updateCustomer , getFriend } from '../../api/yun_customer'
import util from '../../libs/util'
import { checkIdCard } from '../../libs/validate'
export default {
    data() {
        const idCard = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('身份证号不能为空'));
            } else {
                if (checkIdCard(value)) {
                    callback();                    
                }else{
                    callback(new Error('身份证号码不正确'));
                }
                
            }
        }; 
        return {
            periodModal:false,
            pay_periodModal:false,
            pay_periodRadio:'',
            periodRadio:'',
            orglist:[],
            options3:{
                disabledDate(date){
                    return date && date.valueOf() > Date.now() ;
                }
            },
            apptotal:0,
            apppage:1,
            applicant_number:true,
            idrule:{
                 required: true, pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/, message: '请填写证件号', trigger: 'blur' 
            },
            party_modal:false,
            pay_period_disable:true,
            insured_customer_id:'',
            insurances:{
                type:'保险金额',
                pay_periodarry:[],
                periodarry:[],
                pay_period:'',
                period:'',
            },
            insured:{
                insured_name:'',
                name:'',
                id_type:'身份证'
            },
            importpro:false,
            customer:{
                id_type:'身份证'
            },
            customerEdit:true,
            pro_index_tag:0,
            create_or_update:0,
            currentRow:{},
            importbenefit:false,
            tableloading:false,
            spinShow:false,
            addcustomer:false,


            importcustomer:false,

            
            importemployee:false,
            importtype:'',
            canedit:true,
            re_canedit:true,
            closeable:false,
            loading:true,
            proloading:false,
            options1:[],
            comoptions:[],
            prolist:[],
            renewalInsure:{},
            searchemploy:'',
            searchcustom:'',
            beneficiary_type:'指定受益',
            firendlist:[],
            commonlist:[],
            //录单员
            entering:{
                job_code:'',
                name:'',
                datetime:formatTime(new Date(),'yyyy-MM-dd'),
                date:formatTime(new Date(),'yyyy-MM-dd')
            },
            //业务员
            agent:{
                oid:'',
                oname:'',
                dept_id:'',
                dept_name:'',
                rank_id:'',
                rank_name:'',
                name:'',
                eid :'',
                job_code:'',
                leader_name:'',
                leader_id :'',
                rec_name:'',
                rec_id:''
            },
            //保单信息
            policyform:{
                yun_org_mid:'',
                cid:'',
                cname:'',
                name:'',
                insure_num:'',
                policy_num:'',
                pay_type:'',
                premium:0,
                is_short:'2',
                insure_date:formatTime(new Date(),'yyyy-MM-dd'),
                insure_datetime:formatTime(new Date(),'yyyy-MM-dd'),
                underwrite_datetime:'',
                underwrite_date:'',
                effect_datetime:'',
                effect_date:'',
                receipt_datetime:'',
                receipt_date:'',
                visit_datetime:'',
                visit_date:'',
                withdraw_datetime:'',
                withdraw_date:'',
                terminal_datetime:'',
                terminal_date:'',
                settlement_datetime:'',
                settlement_date:'',
                status:'1'
            },
            //投保人信息
            applicant:{
                customer_id:'',
                name:'',
                id_type:'身份证',
                id_number:'',
                mobile:'',
                sex:'',
                birthday:'',
                birthdaytime:'',
                com_name:'',
                profession:'',
                postcode:'',
                email:''
            },
            benefit:{

            },
            //被保人
            policyDetail:{
                insureds:[
                    {
                        relation:'本人',
                        canedit:true,
                        name:'',
                        id_type:'身份证',
                        id_number:'',
                        mobile:'',
                        sex:'',
                        birthday:'',
                        birthdaytime:'',
                        com_name:'',
                        profession:'',
                        insurances:[
                            {
                                mongo_id:'',
                                name:'',
                                period:'',
                                period_arry:[],
                                pay_period:'',
                                pay_period_arry:[],
                                premium:'', 
                                type:'保险金额',
                                amount :''
                            }
                        ],
                        beneficiary_type:'指定受益',
                        beneficiary:[
                            {
                                name:'',
                                id_type:'身份证',
                                id_number:'',
                                mobile:'',
                                relation:'',
                                sex:'',
                                birthday:'',
                                birthdaytime:'',
                                order:'',
                                scale:''
                            }
                        ]
                    }
                ]
            },
            benefittable:[
                {
                    title: '姓名',
                    key: 'name',
                    align:"center",
                },
                {
                    title: '证件号码',
                    key: 'id_number',
                    align:"center",
                },
                {
                    title: '关系',
                    key: 'relation',
                    align:"center",
                },
                {
                    title: '受益顺序',
                    key: 'order',
                    align:"center",
                },
                {
                    title: '收益比例',
                    key: 'scale',
                    align:"center",
                },
                {
                    title: '操作',
                    align:"center",
                    render: (h, params) => {
                        return h('div', [
                            h('Button', {
                                props: {
                                    type: 'error',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {           
                                        this.removebenefit(params.index)
                                    }
                                }
                            }, '删除'),
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.editbenefitlist(params.index)
                                    }
                                }
                            }, '编辑')
                        ]);
                    }
                },
            ],
            benefitdata:[
                
            ],
            protable:[
                {
                    title: '险种名称',
                    key: 'name',
                    align:"center",
                },
                {
                    title: '被保人',
                    key: 'insured_name',
                    align:"center",
                },
                {
                    title: '交费期间',
                    key: 'pay_period',
                    align:"center",
                },
                {
                    title: '保费',
                    key: 'premium',
                    align:"center",
                },
                {
                    title: '保额',
                    key: 'amount',
                    align:"center",
                },
                {
                    title: '操作',
                    align:"center",
                    render: (h, params) => {
                        return h('div', [
                            h('Button', {
                                props: {
                                    type: 'error',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {           
                                        this.remove_pro(params.index)
                                    }
                                }
                            }, '删除'),
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.edit_pro(params.index)
                                    }
                                }
                            }, '编辑')
                        ]);
                    }
                },
            ],
            prodata:[],
            partytable:[
                {
                    title: '姓名',
                    key: 'name',
                    align:"center",
                },
                {
                    title: '证件号码',
                    key: 'id_number',
                    align:"center",
                },
                {
                    title: '关系',
                    key: 'relation',
                    align:"center",
                },
                // {
                //     title: '操作',
                //     align:"center",
                //     render: (h, params) => {
                //         return h('div', [
                //             // h('Button', {
                //             //     props: {
                //             //         type: 'error',
                //             //         size: 'small'
                //             //     },
                //             //     style: {
                //             //         marginRight: '5px'
                //             //     },
                //             //     on: {
                //             //         click: () => {           
                //             //             this.remove_party(params.index)
                //             //         }
                //             //     }
                //             // }, '删除'),
                //             h('Button', {
                //                 props: {
                //                     type: 'primary',
                //                     size: 'small'
                //                 },
                //                 style: {
                //                     marginRight: '5px'
                //                 },
                //                 on: {
                //                     click: () => {
                //                         this.edit_party(params.row.customer_id,params.row.relation)
                //                     }
                //                 }
                //             }, '编辑')
                //         ]);
                //     }
                // },
            ],
            partydata:[],
            columns: [
                {
                    title: '姓名',
                    key: 'name'
                },
                {
                    title: '工号',
                    key: 'job_code',
                    render: (h, params) => {
                        return h('div', {},'工号：'+params.row.job_code);
                    }
                },
                {
                    title: '操作',
                    key: 'address',
                    width:100,
                    align:"center",
                    render: (h, params) => {
                        return h('div', [
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small',
                                },                               
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.impempbtn(params.row.id);
                                        this.searchemploy="";
                                        this.emplist=[];
                                    }
                                }
                            }, '导入')
                        ]);
                    }
                }
            ],
            columnsuser:[
                {
                    title: '姓名',
                    key: 'name',
                    width:100,
                    algin:'center'
                },
                {
                    title: '证件号码',
                    key: 'id_number',
                    algin:'center'
                },
                // {
                //     title: '操作',
                //     key: 'address',
                //     width:100,
                //     align:"center",
                //     render: (h, params) => {
                //         return h('div', [
                //             h('Button', {
                //                 props: {
                //                     type: 'primary',
                //                     size: 'small',
                //                 },                               
                //                 style: {
                //                     marginRight: '5px'
                //                 },
                //                 on: {
                //                     click: () => {
                //                         this.impctm(params.row._id)
                //                     }
                //                 }
                //             }, '导入')
                //         ]);
                //     }
                // }
                
            ],
            columnsrelation:[
                {
                    title: '姓名',
                    key: 'name',
                    width:100,
                    algin:'center'
                },
                {
                    title: '证件号码',
                    key: 'id_number',
                    algin:'center'
                },      
            ],
            appCustomerList:[
                
            ],
            emplist:[

            ],
            insured_ruleValidate:{
                name: [
                    { required: true, message: '请输入姓名', trigger: 'blur',pattern:/^[\u4e00-\u9fa5]+$/ }
                ],
                relation: [
                    { required: true, message: '请选择与投保人关系', trigger: 'change' }
                ],
                id_type: [
                    { required: true, message: '请选择证件类型', trigger: 'change' }
                ],
                id_number: [
                    { validator: idCard, message: '请填写证件号', trigger: 'blur' },
                ],
                sex: [
                    { required: true, message: '请选择性别', trigger: 'change' }
                ],
                birthdaytime: [
                    { required: true, type:'date', message: '请选择日期', trigger: 'change' }
                ],
            },
            insurances_ruleValidate:{
                insured_id:[
                    {required: true, message: '被保人不能为空', trigger: 'change'}  
                ],
                is_main:[
                    {required: true, message: '主附险不能为空', trigger: 'change'}     
                ],
                mongo_id:[
                    {required: true, message: '险种名称不能为空', trigger: 'change'}        
                ],
                period:[
                     {required: true, message: '请选择保险期间', trigger: 'change'}        
                ],
                pay_period:[
                     { required: true, message: '请填写交费期间', trigger: 'change' }
                ],
                premium: [
                    { required: true, type:'number',transform(value) {
                    return parseFloat(value);
                    }, message: '请正确填写保费', trigger: 'blur' }
                ],
                amount: [
                    { required: true, message: '请填写', trigger: 'blur,change' }
                ],
                
            },
            entering_ruleValidate: {
                job_code:[
                    { required: true, message: '请填写录单员工号', trigger: 'change' }
                ],
                name: [
                    { required: true, message: '请填写录单员姓名', trigger: 'change' }
                ],  
                datetime: [
                    { required: true, type: 'date', message: '请选择录单时间', trigger: 'change' }
                ],              
            },
            agent_ruleValidate: {
                // oname:[
                //     { required: true, message: '请选择机构', trigger: 'change' }
                // ],
                // dept_name: [
                //     { required: true, message: '请选择部门', trigger: 'change' }
                // ],
                // rank_name : [
                //     { required: true, message: '请选择职级', trigger: 'change' }
                // ], 
                job_code  : [
                    { required: true, message: '请选择工号', trigger: 'change' }
                ], 
                name: [
                    { required: true, message: '请选择姓名', trigger: 'change' }
                ],
            },
            policy_ruleValidate:{
                yun_org_mid:[
                     { required: true, message: '请选择归属机构', trigger: 'change' }
                ],
                cid:[
                    { required: true, message: '请填写保险公司',transform(value) {
                    return value.toString();
                    }, trigger: 'change' }
                ],
                insure_datetime:[
                    { required: true, type:'date', message: '请填写投保时间', trigger: 'change' }
                ],
                name: [
                    {  message: '请填写保险计划', trigger: 'blur' }
                ],
                insure_num: [
                    { required: true, message: '请填写投保单号', trigger: 'blur',pattern:/^[0-9a-zA-Z]+$/  }
                ], 
                policy_num: [
                    {  message: '请填写保单号', trigger: 'blur',pattern:/^[0-9a-zA-Z]+$/ }
                ], 
                pay_period: [
                    { required: true, message: '请选择交费期间', trigger: 'change' }
                ], 
                period: [
                    { required: true, message: '请选择保险期间', trigger: 'change' }
                ], 
                pay_type: [
                    { required: true, message: '请填写交费方式', trigger: 'change' }
                ], 
                premium: [
                    { required: true, type:'number',transform(value) {
                    return parseFloat(value);
                    }, message: '请正确填写保费', trigger: 'blur' }
                ],
                status:[
                    { required: true, message: '请选择保单状态', trigger: 'change' }
                ],
            },
            applicant_ruleValidate:{
                name:[
                    { required: true, message: '请填写姓名', trigger: 'blur,change' }
                ],
                id_type: [
                    { required: true, message: '请选择证件类型', trigger: 'change' }
                ],
                id_number: [
                    { required: true, pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/, message: '请填写证件号', trigger: 'blur,change' }
                ], 
                mobile: [
                    { pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: '请填写手机号', trigger: 'blur,change' }
                ],  
                sex: [
                    { required: true, message: '请选择性别', trigger: 'change' }
                ],
                birthdaytime: [
                    { required: true, type:'date', message: '请选择日期', trigger: 'change' }
                ],
                postcode:[
                    { pattern: /^[0-9]{6}$/, message: '请正确填写邮编', trigger: 'blur,change' }
                ],
                email: [
                    { type:'email', message: '请正确填写email', trigger: 'blur,change' }
                ],
            },
            customer_ruleValidate:{
                name:[
                    { required: true, message: '请填写姓名', trigger: 'blur' }
                ],
                id_type: [
                    { required: true, message: '请选择证件类型', trigger: 'change' }
                ],
                sex: [
                    { required: true, message: '请选择性别', trigger: 'change' }
                ],
                birthdaytime: [
                    { required: true, type:'date', message: '请选择日期', trigger: 'change' }
                ],
            },
            // insured_ruleValidate:{
            //     name:[
            //         { required: true, message: '请填写姓名', trigger: 'blur' }
            //     ],
            //     id_type: [
            //         { required: true, message: '请选择证件类型', trigger: 'change' }
            //     ],
            //     id_number: [
            //         { required: true, pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/, message: '请填写证件号', trigger: 'blur' }
            //     ], 
            //     mobile: [
            //         { required: true, pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: '请填写手机号', trigger: 'blur' }
            //     ],
            //     sex: [
            //         { required: true, message: '请选择性别', trigger: 'blur,change' }
            //     ],
            //     birthdaytime: [
            //         { required: true, type:'date', message: '请选择生日', trigger: 'blur,change' }
            //     ],
            //     period: [
            //         { required: true, message: '请选择保险期间', trigger: 'change' }
            //     ],
            //     pay_period: [
            //         { required: true, message: '请选择交费期间', trigger: 'change' }
            //     ],
            //     premium: [
            //         { required: true, message: '请填写保费', trigger: 'blur' }
            //     ],
            //     amount: [
            //         { required: true, message: '请填写', trigger: 'blur' }
            //     ],
            //     type: [
            //         { required: true, message: '请选择', trigger: 'change' }
            //     ],
            // }
        }
    },
    components: {
        productTitle
    },
    computed: {
        slidetoggle(){
            return this.$store.state.sildeshow
        },
        policypay_period(){
            let policyarry = []
            for(var i=0;i<this.prodata.length;i++){
                
                policyarry.push(this.prodata[i].pay_period)

            }
            let _arry = Array.from(new Set(policyarry))
            _arry = _arry.filter(function(item){
                return item !== ''
            });
            return _arry
        },
        totalprice(){
            var _total = 0
            for(var i=0;i<this.prodata.length;i++){
                //_total += this.formatFloat(this.prodata[i].premium)
               _total =  this.formatFloat(_total , this.prodata[i].premium )
            }
            return _total
        },
        hasctmid(){
            if(this.customer.customer_id){
                return false
            }else{
                return true
            }
        },
        hasagent(){
            if(this.agent.eid){
                return false
            }else{
                return true
            }
        },
        hasapp(){
            if(this.applicant.customer_id){
                return false
            }else{
                return true
            }
        },
        hasben(){
            if(this.benefit.customer_id){
                return false
            }else{
                return true
            }
        },
        hasIdCard(){
            if(this.applicant.id_type == '身份证'){
                //this.applicant_number = true
                return true
            }else{
                return false
                //this.applicant_number = false
            }
        }
    },
    watch:{
        prodata:function(val,oldval){
            console.log(val)
            var _length = val.length;
            var _arry = []
            if(_length > 0){
                this.policyform.premium = 0
                this.pay_period_disable = false
                for(var i = 0;i<_length;i++){
                    //this.policyform.premium = this.formatFloat(this.policyform.premium + this.formatFloat(val[i].premium,2),2)
                    this.policyform.premium = this.formatFloat(this.policyform.premium,val[i].premium)
                    //console.log(this.formatFloat(val[i].premium,2)) 
                    _arry.push(val[i].pay_period)
                }
                let _pay_period = Array.from(new Set(_arry))
                _pay_period = _pay_period.filter(function(item){
                    return item !== ''
                });
                this.policyform.pay_period = _pay_period.sort()[0]
            }
        }
    },
    mounted () {
      this.cominit() 
      this.orglistinit()
      //console.log(checkIdCard('230781198502174736'))
      //console.log(this.formatFloat(0,23.56)) 
    },
    methods: {
        openPeriodModal(){
            this.periodModal = true
        },
        openPayperiodModal(){
            this.pay_periodModal = true
        },
        orglistinit(){
            new Promise((resolve, reject) => {
            let _params = {
                name:''
            }
            getListByName(_params).then(response => {
                    console.log(response.data)
                    if (response.data.err == 0) {               
                        this.orglist = response.data.data;
                        
                        
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        relationCurrentChange(currentRow,oldCurrentRow){
            console.log(currentRow)
            console.log(oldCurrentRow)

            this.currentRow = currentRow
            console.log(this.currentRow)
            console.log(this.applicant.customer_id)
            this.importctminfo(this.currentRow._id,this.applicant.customer_id).then( (data) =>{ 
                this.insured = data
                this.insured.sex = this.insured.sex.toString()
                this.insured.birthdaytime = this.insured.birthday
            })
        },
        //新增关系人
        addrelationbtn(){
            console.log(this.applicant.customer_id)
            if(!this.applicant.customer_id){
                this.$Message.error('请先导入被保人')
            }else{
                this.re_canedit = false
            }
            
        },
        editrelationbtn(){
            if(!this.applicant.customer_id){
                this.$Message.error('请先导入被保人')
            }else{
                this.re_canedit = false
            }
        },
        //取消新增
        cancelrelation(){
            this.re_canedit = true
            this.$refs['insured'].resetFields()
            this.insured = {
                id_type:'身份证'
            }
        },
        saverelation(){
            this.import_party()
        }, 
        pageChange(page){
            this.apppage = page
            this.getcustomer()
        },
        tofixed2(number){
            var num1=Number(number).toFixed(3);
            num1 = num1.substring(0,num1.lastIndexOf('.')+3);
            return num1
        },
        formatFloat(oldnmuber,newnumber){
            var number1 = this.tofixed2(oldnmuber)*100
            var number2 = this.tofixed2(newnumber)*100
            return (number1 + number2) / 100
        },
        cid_change(e){
            if(e.value&&e.label){
                this.policyform.cname = e.label
            }
        },
        cancel_insurances(){
            this.importpro = false
        },
        cancel_party(){
            this.party_modal = false
        },
        edit_party(id,relation){
            this.importctminfo(id).then(data=>{
                console.log(data)
                this.insured = data
                this.insured.relation = relation
                this.insured.sex = this.insured.sex.toString()
                this.insured.birthdaytime = this.insured.birthday
                this.party_modal = true
            })
        },
        import_party(){
            if(this.agent.eid){
                this.insured.agent_id = this.agent.eid
                this.$refs['insured'].validate((valid) => {
                    if (valid) {
                        this.insured.applicant_id = this.applicant.customer_id
                        if(!this.insured.id){
                            //创建客户
                            
                            new Promise((resolve, reject) => {
                                createCustomer(this.insured).then(response => {
                                    console.log(response.data)
                                    if (response.data.err == 0) {                           
                                        this.canedit = true
                                        this.re_canedit = true
                                        //this.party_modal = false
                                        this.getcustomer()
                                        this.getbenefit()
                                    } else {
                                        this.$Message.error(response.data.info);
                                    }
                                    resolve();
                                }).catch(error => {
                                    reject(error);
                                });
                            });
                        }else{
                            // 更新客户
                            this.insured.customer_id = this.insured.id
                            new Promise((resolve, reject) => {
                                updateCustomer(this.insured).then(response => {
                                        console.log(response.data)
                                        if (response.data.err == 0) {                           
                                            this.party_modal = false
                                            this.getbenefit()
                                            this.$Message.success(response.data.info);
                                        } else {
                                            this.$Message.error(response.data.info);
                                        }
                                        resolve();
                                    }).catch(error => {
                                        reject(error);
                                    });
                            });
                        }                       
                    }else{
                        this.$Message.error("请输入正确的信息")
                    } 
                })
            }else{
                this.$Message.error("请先导入业务员信息")
            }
        },
        open_party_modal(){
            this.$refs['insured'].resetFields()
            this.insured = {
                id_type:'身份证'
            }
            this.party_modal = true
        },
        add_insured(){
            this.$refs['insured'].resetFields()
            // delete this.insured.
            this.insured = {
                 id_type:'身份证'
            }
            this.canedit = false
        },
        insured_save(){
            if(this.agent.eid){
                this.insured.agent_id = this.agent.eid
                this.$refs['insured'].validate((valid) => {
                    if (valid) {
                        this.insured.name = this.insured.insured_name
                        this.insured.relation = this.insured.insured_relation
                        this.insured.applicant_id = this.applicant.customer_id
                        if(!this.insured.id){
                            //创建客户
                            
                            new Promise((resolve, reject) => {
                                createCustomer(this.insured).then(response => {
                                        console.log(response.data)
                                        if (response.data.err == 0) {                           
                                            this.canedit = true
                                            this.insured.customer_id = response.data.data
                                        } else {
                                            this.$Message.error(response.data.info);
                                        }
                                        resolve();
                                    }).catch(error => {
                                        reject(error);
                                    });
                            });
                        }else{
                            // 更新客户
                            this.insured.customer_id = this.insured.id
                            new Promise((resolve, reject) => {
                                updateCustomer(this.insured).then(response => {
                                        console.log(response.data)
                                        if (response.data.err == 0) {                           
                                            this.canedit = true
                                        } else {
                                            this.$Message.error(response.data.info);
                                        }
                                        resolve();
                                    }).catch(error => {
                                        reject(error);
                                    });
                            });
                        }                       
                    }else{
                        this.$Message.error("请填写正确信息")
                    } 
                })
            }else{
                this.$Message.error("请先导入业务员信息")
            }
        },
        remove_pro(index){
            this.prodata.splice(index,1)
        },
        edit_pro(index){
            this.insurances = Object.assign({},this.prodata[index])
            this.pro_index_tag = index
            this.create_or_update = 0
            this.importpro = true
        },
        import_insurances(){
            // this.hasctmid=true;
            // setTimeout(()=>{
            //      this.hasctmid=false;
            // },1000)
            this.$refs['insurances'].validate((valid) => {
                if(valid){
                        this.importctminfo(this.insurances.insured_id).then(data=>{

                            this.insurances.insured_customer_id = this.insurances.insured_id
                            this.insurances.insured_name = data.name
                            this.insurances.insured_id_type = data.id_type
                            this.insurances.insured_id_number = data.id_number
                            this.insurances.insured_mobile = data.mobile
                            this.insurances.insured_sex = data.sex
                            this.insurances.insured_com_name = data.com_name
                            this.insurances.insured_profession = data.profession
                            this.insurances.insured_birthday = data.birthday
                            if(this.create_or_update > 0){
                                this.prodata.push(Object.assign({},this.insurances))
                            }else{
                                this.prodata.splice(this.pro_index_tag,1,Object.assign({},this.insurances))
                            }
                            
                            this.importpro = false 
                        })                                                           
                }else{
                    this.$Message.error("请完善信息");
                }               
            })
        },
        open_pro_modal(){
            this.$refs['insurances'].resetFields()
            this.$refs['insured'].resetFields()
            this.insured.insured_customer_id = ''
            this.create_or_update = 1
            this.prodatatag = -1
            this.importpro = true
            this.canedit = true
        },
        insured_change(e){
            console.log(e)
            if(e.label&&e.value){
                this.insurances.insured_relation = e.label.split("-")[2]
                
            }            
        },
        pro_change(e){
            console.log(e)
            if(e.value&&e.label){
                this.insurances.name = e.label
                this.get_pro_detail(e.value)
            }       
        },
        get_pro_detail(id){            
            new Promise((resolve, reject) => {
                let _params = {
                    mongo_id:id
                }
                getDetailByIdProduct(_params).then(response => {
                    console.log(response.data)
                    if (response.data.err == 0) {                       
                        this.insurances.cate_one =  response.data.data.cate_one 
                        this.insurances.periodarry = response.data.data.period
                        this.insurances.pay_periodarry = response.data.data.pay_period
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    
                }).catch(error => {
                    reject(error);
                });
            });
        },
        getpro(is_main){
            if(this.policyform.cid){
                new Promise((resolve, reject) => {
                    let _params = {
                        cid :this.policyform.cid,
                        is_main:is_main
                    }
                    getListByCom(_params).then(response => {
                        console.log(response.data)
                        if (response.data.err == 0) {                                                   
                            this.options1 = response.data.data
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        
                    }).catch(error => {
                        reject(error);
                    });
                });
            }else{
                this.$Message.error("请先在保单信息中选择保险公司")
                
            }
            
        },
        is_main_change(value){
            if(value){
                this.getpro(value)
            }  
        },
        editbenefitlist(index){
            console.log(index)
           this.benefit = this.benefitdata[index]
           this.benefit.index = index
           console.log(this.benefitdata[index])
           this.importbenefit = true
        },
        removebenefit(index){
            this.benefitdata.splice(index,1)
        },
        cancelbenefit(){
            this.benefit.name="";
            this.benefit.id_type="";
            this.benefit.id_number="";
            this.benefit.sex="";
            this.benefit.birthdaytime="";
            this.benefit.relation="";
            this.benefit.order="";
            this.benefit.scale="";
            this.canedit=true;
        },
        sevebenefit(){
            // if(this.agent.eid){
            //     this.benefit.agent_id = this.agent.eid
            //     this.$refs['benefit'].validate((valid) => {
            //         if (valid) {
            //             if(!this.benefit.customer_id){
            //                 //创建客户
            //                 new Promise((resolve, reject) => {
            //                     createCustomer(this.benefit).then(response => {
            //                             console.log(response.data)
            //                             if (response.data.err == 0) {                           
            //                                 this.canedit = true
            //                                 this.customer.customer_id = response.data.data
            //                             } else {
            //                                 this.$Message.error(response.data.info);
            //                             }
            //                             resolve();
            //                         }).catch(error => {
            //                             reject(error);
            //                         });
            //                 });
            //             }else{
            //                 // 更新客户
            //                 new Promise((resolve, reject) => {
            //                     updateCustomer(this.benefit).then(response => {
            //                             console.log(response.data)
            //                             if (response.data.err == 0) {                           
            //                                 this.canedit = true
            //                             } else {
            //                                 this.$Message.error(response.data.info);
            //                             }
            //                             resolve();
            //                         }).catch(error => {
            //                             reject(error);
            //                         });
            //                 });
            //             }                       
            //         }else{
            //             this.$Message.error("请完善信息")
            //         } 
            //     })
            // }else{
            //     this.$Message.error("请先导入业务员信息")
            // }
            this.canedit = true
        },
        //编辑受益人
        editbenefit(){
            this.canedit = false
        },
        //新增受益人信息
        addbenefit(){
            this.$refs['benefit'].resetFields()
            this.canedit = false
        },
        //受益方式切换
        benefit_change(value){
            console.log(value)
            if(value == '法定受益'){
                this.benefitdata = []
            }
        },
        //导入受益人
        importbenefitbtn(){
            if(this.benefit.index != null){
                this.benefitdata.splice(this.benefit.index,1,this.benefit)
            }else{
                this.benefitdata.push(this.benefit)
                
            }
            this.importbenefit = false
        },
        cancelbenefitbtn(){
            this.importbenefit = false
        },
        //新增受益人
        importbenfit(){
            this.importbenefit = true
        },
        //受益人改变
        bftchange(e){
            console.log(e)
            this.importctminfo(e.value).then(data=>{
                console.log(data)
                this.benefit = data
                this.benefit.customer_id = data.id
                this.benefit.sex = this.benefit.sex.toString()
                this.benefit.birthdaytime = this.benefit.birthday
                this.benefit.relation = e.label.split("-")[2]
            })

        },
        //更改投保人
        editcustomerbtn(){
            this.canedit = false
        },        
        //导入投保人
        importapp(){
            if(this.customer.customer_id){
                this.applicant = Object.assign({},this.applicant,this.customer)
                this.importcustomer = false
                this.getbenefit()
            }else{
                this.$Message.error("请先选择投保人")
            }
        },
        tableCurrentChange(currentRow,oldCurrentRow){
            this.customerEdit = false
            console.log(currentRow)
            console.log(oldCurrentRow)
            this.tableaction = false;
            this.currentRow = currentRow
            console.log(this.currentRow)
            this.importctminfo(this.currentRow._id).then( (data) =>{ 
                this.customer = data
                this.customer.customer_id = data.id
                delete this.customer.id
                this.customer.sex = this.customer.sex.toString()
                this.customer.birthdaytime = this.customer.birthday
            })
        },
        //获取投保人详细信息
        importctminfo(id,type){
            return new Promise((resolve, reject) => {
                let _params = {
                    agent_id:this.agent.eid,
                    customer_id:id,
                    applicant_id:type?type:0
                }
                getDetailById(_params).then(response => {
                    console.log(response.data)
                    if (response.data.err == 0) {                                                   
                        resolve(response.data.data)
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    
                }).catch(error => {
                    reject(error);
                });
            });
        },
        //保存客户
        savecustomer(){
            if(this.agent.eid){
                this.customer.agent_id = this.agent.eid
                this.$refs['customer'].validate((valid) => {
                    if (valid) {
                        if(!this.customer.customer_id){
                            //创建客户
                            new Promise((resolve, reject) => {
                                createCustomer(this.customer).then(response => {
                                        console.log(response.data)
                                        if (response.data.err == 0) {                           
                                            this.canedit = true
                                            //this.customer.customer_id = response.data.data
                                            this.apppage = 1
                                            this.getcustomer()
                                            this.customerEdit = true
                                        } else {
                                            this.$Message.error(response.data.info);
                                        }
                                        resolve();
                                    }).catch(error => {
                                        reject(error);
                                    });
                            });
                        }else{
                            // 更新客户
                            new Promise((resolve, reject) => {
                                updateCustomer(this.customer).then(response => {
                                        console.log(response.data)
                                        if (response.data.err == 0) {                           
                                            this.canedit = true
                                            this.apppage = 1
                                            this.getcustomer()
                                            this.customerEdit = true
                                        } else {
                                            this.$Message.error(response.data.info);
                                        }
                                        resolve();
                                    }).catch(error => {
                                        reject(error);
                                    });
                            });
                        }                       
                    }else{
                        this.$Message.error("请填写正确信息")
                    } 
                })
            }else{
                this.$Message.error("请先导入业务员信息")
            }
        },
        //新增客户
        addcustomerbtn(){
            this.canedit = false
            this.$refs['customer'].resetFields();
            this.customer = {
                id_type:'身份证'
            }
        },
        //取消新增客户
        cancelcustomer(){
            this.$refs['customer'].resetFields();
            this.canedit = true 
            this.customer = {
                id_type:'身份证'
            }
        },
        //关闭投保人
        cancel(){
            this.importcustomer = false
        },
        idcardchange(e,obj){
            if(obj.id_type == '身份证'){           
                let _length = e.target.value.length
                if( _length == 18){
                    obj.birthdaytime = util.GetBirthday(e.target.value)
                    obj.birthday = util.GetBirthday(e.target.value)
                    var _sex = util.Getsex(e.target.value)+''
                    this.$set(obj,'sex',_sex)
                }
            }
        },
        //请求firend
        getbenefit(){
            new Promise((resolve, reject) => {
                let _params = {
                    agent_id:this.agent.eid,
                    applicant_id:this.applicant.customer_id
                }
                getFriend(_params).then(response => {
                        console.log(response.data)
                        if (response.data.err == 0) {                           
                            this.firendlist = response.data.data;
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
            });
        },
        cominit(){
            console.log(this.$refs)
            new Promise((resolve, reject) => {
                let _params = {
                    name:''
                }
                parteGetByName(_params).then(response => {
                        console.log(response.data)
                        if (response.data.err == 0) {                           
                            this.comoptions = response.data.data;
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
            });
        },
        surebtn(){

        },
        companychange(item){
            //console.log(item)
            this.policyform.cname = item.label
        },
        prochange(e,pindex,index){
            if(e.label){
                console.log(e)
                console.log(pindex)
                console.log(index)
                let items = this.prolist.filter(item=>item.label==e.label)
                console.log(items)
                this.policyDetail.insureds[pindex].insurances[index].name = e.label
                this.policyDetail.insureds[pindex].insurances[index].period = ''
                this.policyDetail.insureds[pindex].insurances[index].pay_period = ''
                this.policyDetail.insureds[pindex].insurances[index].period_arry = items[0].period
                this.policyDetail.insureds[pindex].insurances[index].pay_period_arry = items[0].pay_period
            }           
        },
        //远程请求保险公司
        remoteCom(query){
            if (query !== '') {
                this.proloading = true;
                setTimeout(() => {
                    
                    new Promise((resolve, reject) => {
                        let _params = {
                            name:query,
                        }
                        parteGetByName(_params).then(response => {
                            console.log(response.data)
                            if (response.data.err == 0){
                                 this.proloading = false;
                                const list = response.data.data.map(item => {
                                    return {
                                        value: item.cid,
                                        label: item.name,
                                        pay_period:item.pay_period,
                                        period:item.period
                                    };
                                });
                                this.comoptions = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1);                   
                            } else {
                                this.$Message.error(response.data.info);
                            }
                            resolve();
                        }).catch(error => {
                            reject(error);
                        });
                    });                   
                }, 200);
            } else {
                this.comoptions = [];
            }
        },
        //远程请求险种
        // remoteMethod1 (query) {
        //     console.log(query)
        //     if (query !== '') {
        //         this.proloading = true;
        //         setTimeout(() => {
        //             let _params = {
        //                 name:query,
        //             }
        //             new Promise((resolve, reject) => {
                        
        //                 proGetByName(_params).then(response => {
        //                     console.log(response.data)
        //                     if (response.data.err == 0){
        //                          this.proloading = false;
        //                         const list = response.data.data.map(item => {
        //                             return {
        //                                 value: item.id,
        //                                 label: item.name,
        //                                 pay_period:item.pay_period,
        //                                 period:item.period
        //                             };
        //                         });
        //                         this.prolist = list
        //                         this.options1 = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1);                   
        //                     } else {
        //                         this.$Message.error(response.data.info);
        //                     }
        //                     resolve();
        //                 }).catch(error => {
        //                     reject(error);
        //                 });
        //             });                   
        //         }, 200);
        //     } else {
        //         this.options1 = [];
        //     }
        // },
        //删除被保人
        delinsured(index){           
            this.policyDetail.insureds.splice(index,1)
            console.log(this.policyDetail.insureds.length)
            if(this.policyDetail.insureds.length == 0){
                this.addinsured()
            }
        },
        //追加被保人
        addinsured(){
            this.policyDetail.insureds.push(
                {
                    relation:'本人',
                    canedit:true,
                    name:'',
                    id_type:'身份证',
                    id_number:'',
                    mobile:'',
                    sex:'',
                    birthday:'',
                    com_name:'',
                    profession:'',
                    insurances:[
                        {
                            mongo_id:'',
                            name:'',
                            period:'',
                            period_arry:[],
                            pay_period:'',
                            pay_period_arry:[],
                            premium:'', 
                            type:'保险金额',
                            amount :''
                        }
                    ],
                    beneficiary_type:'指定受益',
                    beneficiary:[
                        {
                            name:'',
                            id_type:'身份证',
                            id_number:'',
                            mobile:'',
                            relation:'',
                            sex:'',
                            birthday:'',
                            order:'',
                            scale:''
                        }
                    ]
                }
            )
        },
        //添加险种
        addpro(pindex,sindex){
            this.policyDetail.insureds[pindex].insurances.push(
                {
                    mongo_id:'',
                    name:'',
                    period:'',
                    period_arry:[],
                    pay_period:'',
                    pay_period_arry:[],
                    premium:'', 
                    type:'保险金额',
                    amount :''
                }
            )
        },
        //删除险种
        delpro(pindex,sindex){
            this.policyDetail.insureds[pindex].insurances.splice(sindex,1)
            if(this.policyDetail.insureds[pindex].insurances.length == 0){
                this.addpro(pindex,sindex)
            }
        },
        //追加受益人
        // addbenefit(pindex){
        //     this.policyDetail.insureds[pindex].beneficiary.push(
        //         {
        //             name:'',
        //             id_type:'身份证',
        //             id_number:'',
        //             mobile:'',
        //             relation:'',
        //             sex:'',
        //             birthday:'',
        //             order:'',
        //             scale:''
        //         }
        //     )
        // },
        //删除受益人
        delbenefit(pindex,bindex){
            this.policyDetail.insureds[pindex].beneficiary.splice(bindex,1)
            if(this.policyDetail.insureds[pindex].beneficiary.length == 0){
                this.addbenefit(pindex)
            }
        },
        radiochange(obj,index){
            if(obj !== "本人"){
                this.policyDetail.insureds[index].canedit = false
            }else{
                this.policyDetail.insureds[index].canedit = true
            }
        },
        benefitchange(obj,index){
            if(obj == "法定受益"){
                this.policyDetail.insureds[index].beneficiary = []
            }else{
                this.policyDetail.insureds[index].beneficiary = [
                    {
                        name:'',
                        id_type:'身份证',
                        id_number:'',
                        mobile:'',
                        relation:'',
                        sex:'',
                        birthday:'',
                        order:'',
                        scale:''
                    }
                ]
            }
        },
        //时间转换
        datachange(date,obj,param){
            obj[param] = date
            if(param == 'underwrite_date'){
                if(obj['settlement_datetime'] == ''){
                    obj['settlement_datetime'] = date
                }
                
            }
        },
        importEmployee(type){
            this.importemployee = true
            this.importtype = type
        },
        importapplicant(type){
            this.importcustomer = true
            this.importtype = type
            this.getcustomer()
        },
        //获取险种
        proGetByName(){

        },
        //获取客户信息
        getcustomer(cl){
            this.customerEdit = true
            if(cl){
                this.apppage = 1
            }
            if(!this.agent.eid){
                this.$Message.error("请先导入业务员信息")
                return false
            }
            new Promise((resolve, reject) => {
                let _params = {
                    name:this.searchcustom,
                    agent_id:this.agent.eid,   //this.agent.eid 
                    p:this.apppage  
                }
                getByNameCustomer(_params).then(response => {
                    console.log(response.data)
                    if (response.data.err == 0){
                           this.appCustomerList = response.data.data.list
                           this.apptotal = response.data.data.total                
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },

        //导入员工
        impempbtn(id){
            this.getemployee(id)
        },
        //获取员工详细信息
        getemployee(id){
            new Promise((resolve, reject) => {
                let _params = {
                    id:id
                }
                getById(_params).then(response => {
                    console.log(response.data)
                    if (response.data.err == 0){
                       if(this.importtype == 1){
                           this.entering = Object.assign(this.entering,response.data.data)
                       }
                       if(this.importtype == 2){
                           this.agent = Object.assign(this.agent,response.data.data)
                       }
                       this.importemployee = false
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        //员工搜索 by name
        searchemp(){
           // this.searchemploy
           this.tableloading = true
            new Promise((resolve, reject) => {
                let _params = {
                    name:this.searchemploy
                }
                getByName(_params).then(response => {
                    this.tableloading = false
                    if (response.data.err == 0) {
                        this.emplist = response.data.data
                    } else {
                        this.$Message.error('请先填写姓名');
                    }
                    resolve();
                }).catch(error => {
                    this.tableloading = false
                    reject(error);
                });
            });
        },
        sendpolicy(){
            //'entering','agent','policyform','applicant'
            let successtag = 0
            let formarry = ['entering','agent','policyform','applicant']
            for(var i=0;i<formarry.length;i++){
                this.$refs[formarry[i]].validate((valid) => {
                if (valid) {                       
                    } else {
                        successtag++
                    }
                })
            }
            console.log(successtag)
            if(successtag == 0){
                if(this.prodata.length > 0){
                    this.spinShow = true
                    let _obj = {}
                    _obj.entering = this.entering
                    _obj.agent = this.agent
                    _obj.policyform =this.policyform
                    _obj.applicant = this.applicant
                    _obj.insurances  = this.prodata
                    _obj.beneficiary_type = this.beneficiary_type
                    _obj.beneficiaries = this.benefitdata
                    new Promise((resolve, reject) => {
                        policyCreate(_obj).then(response => {
                            console.log(response.data)
                            if (response.data.err == 0) {
                                this.$Message.success(response.data.info);
                                this.$router.push({ name: 'underwrite_policy' });                           
                            } else {
                                this.spinShow = false
                                this.$Message.error(response.data.info);
                            }
                            resolve();
                        }).catch(error => {
                            this.spinShow = false
                            reject(error);
                        });
                    }); 
                    // _obj.insureds = this.policyDetail.insureds
                }else{
                    this.$Message.error("请完善险种信息")
                }
            }else{
                this.$Message.error("请完善必填信息！");
            }
            // if(successtag == 0){
            //     let _insureds = this.policyDetail.insureds
            //     for(var i=0;i<_insureds.length;i++){
            //         if(_insureds[i].relation == "本人"){
            //             _insureds[i].name = this.applicant.name
            //             _insureds[i].id_type  = this.applicant.id_type 
            //             _insureds[i].id_number  = this.applicant.id_number 
            //             _insureds[i].mobile = this.applicant.mobile
            //             _insureds[i].sex  = this.applicant.sex 
            //             _insureds[i].birthday = this.applicant.birthday
            //             _insureds[i].birthdaytime = this.applicant.birthdaytime
            //             _insureds[i].com_name = this.applicant.com_name
            //             _insureds[i].profession = this.applicant.profession 
            //         }
            //     }
            // }
            // for(var i =0 ;i<this.$refs['insureds'].length;i++){
            //     this.$refs['insureds'][i].validate((valid) => {
            //     if (valid) {                   
            //         } else {
            //             console.log(i)
            //             successtag++
            //         }
            //     })
            // }
            // console.log(successtag)
            // if(successtag == 0){
            //     this.spinShow = true
            //     let _obj = {}
            //     _obj.entering = this.entering
            //     _obj.agent = this.agent
            //     _obj.policyform =this.policyform
            //     _obj.applicant = this.applicant
            //     _obj.insureds = this.policyDetail.insureds
            //     console.log(_obj)
            //     console.log(JSON.stringify(_obj))
            //     new Promise((resolve, reject) => {
            //         policyCreate(_obj).then(response => {
            //             console.log(response.data)
            //             if (response.data.err == 0) {
            //                 this.$Message.success(response.data.info);
            //                 this.$router.push({ name: 'underwrite_policy' });                           
            //             } else {
            //                 this.spinShow = false
            //                 this.$Message.error(response.data.info);
            //             }
            //             resolve();
            //         }).catch(error => {
            //             this.spinShow = false
            //             reject(error);
            //         });
            //     });  
            // }else{
            //     this.$Message.error("请完善必填信息！");
            // }                     
        },
        resetform(){
            this.$refs['entering'].resetFields();
            this.$refs['agent'].resetFields();
            this.$refs['policyform'].resetFields();
            this.$refs['applicant'].resetFields();
            //this.$refs['insureds'][0].resetFields();
            //this.$refs['insureds'].resetFields();
            //console.log(this.$refs['insureds'])
            for(var i =0 ;i<this.$refs['insureds'].length;i++){
                this.$refs['insureds'][i].resetFields();
            }
            console.log(this.$refs['insureds'][0])
            console.log(this.$refs)
        },
        cancelpolicy(){
            this.$router.push({'name':'underwrite_policy'});
        }
    }
}
</script>
